// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/elemac/api/BaDeviceApiControllerApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/elemac/model/BaDeviceQueryReq'

const CLIENT = CORE.grpcCLIENT(Client)

const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return !CORE.isEmpty(param.statusList)
  },
  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'baDeviceQuery', DTO)
    return [resp.comQuery.totalCount, resp.baDeviceDtos || [], { 1: resp.normalCount, 2: resp.faltCount }]
  },
  transList(arr) {
    return arr.map(({ deviceDto = {}, yxzt = {}, gzzt = {}, sbqt = {}, baDevicePropertyDtos, ...other }) => ({
      ...deviceDto,
      ...other,
      yxzt,
      gzzt,
      sbqt,
      propList: baDevicePropertyDtos,
      detailId: deviceDto.id,
    }))
  },
}
